package cn.monkey.transport.core;

import reactor.core.publisher.Mono;

public interface Exchange {
    String KEY = "EXCHANGE";

    String id();

    ExchangeContext context();

    default <T> T setAttribute(String key, T val) {
        return this.context().setAttribute(key, val);
    }

    default <T> T getAttribute(String key) {
        return this.context().getAttribute(key);
    }

    Inbound inbound();

    Outbound outbound();

    default Mono<Void> destroy() {
        return this.close();
    }

    Mono<Void> close();

    boolean isActive();

    default Mono<Void> write(Object o) {
        return this.outbound().write(o);
    }

    default Mono<Void> flush() {
        return this.outbound().flush();
    }

    default Mono<Void> writeAndFlush(Object o) {
        return this.outbound().writeAndFlush(o);
    }

    Exchange bind();
}
